package com.activity;

import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;

import com.api.param.ChangePwdParam;
import com.api.viewModel.LoginVM;
import com.example.apple.ddhr_new.R;
import com.example.apple.ddhr_new.utils.ToastUtil;
import com.example.lzbase.BaseViewModelActivity;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ChangePwdActivity extends BaseViewModelActivity<LoginVM> {


    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.ed_code)
    EditText edCode;
    @BindView(R.id.et_pwd)
    EditText etPwd;

    @Override
    protected int titleText() {
        return R.string.xiugai_mima;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_change_pwd;
    }


    @Override
    protected void created(@Nullable Bundle savedInstanceState) {
        super.created(savedInstanceState);
        etPhone.setText(App.getInstance().getAccount().getUsername());
        viewModel.resetPwd.observe(this,res->{
            finish();
        });

    }

    @OnClick(R.id.btn_denglu)
    public void onViewClicked() {


        if (edCode.getText().toString().length() == 0) {
            ToastUtil.toast(this, R.string.qing_shu_ru_jiu_mima);
            return;
        }


        if (etPwd.getText().toString().length() == 0) {
            ToastUtil.toast(this, R.string.qing_shu_ru_xin_mi_ma);
            return;
        }


        addSubscription(viewModel.resetPassword(new ChangePwdParam(App.getInstance().getAccount().getUsername(),edCode.getText().toString(),etPwd.getText().toString())));


    }


    @OnClick({R.id.btn_oldmima, R.id.btn_mima})
    public void onViewClicked(View view) {
        view.setSelected(!view.isSelected());
        switch (view.getId()) {

            case R.id.btn_oldmima:


                if (view.isSelected()) {
                    edCode.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                } else {
                    edCode.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
                break;
            case R.id.btn_mima:

                if (view.isSelected()) {
                    etPwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                } else {
                    etPwd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
                break;
        }
    }
}
